package com.hxht.cmp.service.impl;

import com.github.pagehelper.PageHelper;
import com.hxht.cmp.common.Constants;
import com.hxht.cmp.entity.*;
import com.hxht.cmp.mapper.*;
import com.hxht.cmp.pojo.BasisCourt;
import com.hxht.cmp.pojo.SearchCriteria;
import com.hxht.cmp.service.CaseReviewService;
import com.hxht.cmp.utils.BeanToMap;
import com.hxht.cmp.utils.CourtUidListUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;

/**
 * 案件回顾相关
 */
@Service
public class CaseReviewServiceImpl implements CaseReviewService {
    @Autowired
    private PlanMapper planMapper;
    @Autowired
    private CaseMapper caseMapper;
    @Autowired
    private TrialMapper trialMapper;
    @Autowired
    private UserMapper userMapper;

    /**
     * @param courtUid
     * @param size
     * @param status   0表示单个发法院，1表示区域法院
     * @return
     */
    @Override
    public List<Map<String, Object>> getReviewIndex(String courtUid, String size, String status) {
        List<Map<String, Object>> result = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //获取参数id法院
        Court nowCourt = Constants.COURT_MAP.get(courtUid);
        Example example = new Example(Plan.class);
        Example.Criteria criteria = example.createCriteria();
        if ("0".equals(status)) {
            criteria.andEqualTo("courtUid", courtUid);
        } else {
            //如果是全局查询，若参数id与当前法院id相同则不要courtid的条件，不同则用in
            if (!Objects.equals(courtUid, Constants.CENTRAL_COURT.getUid())) {
                List<String> courtUids = new ArrayList<>();
                for (Court court : Constants.COURT_LIST) {
                    if (Objects.equals(courtUid, court.getUid()) || Objects.equals(nowCourt.getUid(), court.getParentUid())) {
                        courtUids.add(court.getUid());
                    }
                }
                criteria.andIn("courtUid", courtUids);
            }
        }

        criteria.andGreaterThan("status", 1);
        criteria.andLessThanOrEqualTo("startDate", format.format(new Date()));
        criteria.andEqualTo("active", 1);
        example.setOrderByClause("start_date desc,last_updated desc");
        example.setDistinct(false);
        PageHelper.startPage(1, Integer.parseInt(size));
        List<Plan> plans = planMapper.selectByExample(example);
        if (plans.size() < 1) {
            return result;
        }
        //查询对应的全部Case信息
        List<String> caseIds = new ArrayList<>();
        for (Plan plan : plans) {
            caseIds.add(plan.getCaseUid());
        }
        List<Case> cases = new ArrayList<>();
        if (caseIds.size() > 0) {
            Example caseExample = new Example(Case.class);
            Example.Criteria criteriaOfCase = caseExample.createCriteria();
            criteriaOfCase.andIn("uid", caseIds);
            cases = caseMapper.selectByExample(caseExample);
        }

        for (Plan plan : plans) {
            Map<String, Object> toMap = BeanToMap.beanToMap(plan);
            CourtRoom courtRoom = Constants.COURTROOM_MAP.get(plan.getCourtRoomUid());
            toMap.put("courtroomName", ObjectUtils.isEmpty(courtRoom)?"未知":courtRoom.getName());
            toMap.put("startDate", format.format(toMap.get("startDate")));
            for (Case casetemp : cases) {
                if (Objects.equals(casetemp.getUid(), plan.getCaseUid())) {
                    CaseType caseType = Constants.CASE_TYPE_MAP.get(casetemp.getCategory());
                    toMap.put("caseName", casetemp.getName());
                    toMap.put("caseTypeId", casetemp.getCategory());
                    toMap.put("caseTypeName", ObjectUtils.isEmpty(caseType)?"未知":caseType.getName());
                }
            }

            result.add(toMap);
        }

        return result;
    }

    @Override
    public Integer countReviewByConditions(SearchCriteria searchCriteria) {
        //设置分页开始点
        searchCriteria.setPageStart((searchCriteria.getPage() - 1) * searchCriteria.getPageSize());
        //预设结果
        int count = -1;
        if (Objects.equals(searchCriteria.getStatus(), "0") && Objects.equals(searchCriteria.getReview(), "0")) {
            count = planMapper.getPlanCountByConditions(searchCriteria);

        } else if (Objects.equals(searchCriteria.getStatus(), "0") && Objects.equals(searchCriteria.getReview(), "1")) {
            count = planMapper.getReviewCountByConditions(searchCriteria);
        } else if (Objects.equals(searchCriteria.getStatus(), "1")) {
            String courtUid = searchCriteria.getCourtUid();
            if (!Objects.equals(courtUid, Constants.CENTRAL_COURT.getUid())) {
                List<String> courtUids = new ArrayList<>();
                for (Court court : Constants.COURT_LIST) {
                    if (Objects.equals(courtUid, court.getUid()) || Objects.equals(courtUid, court.getParentUid())) {
                        courtUids.add(court.getUid());
                    }
                }
                searchCriteria.setCourtIdList(courtUids);
                searchCriteria.setCourtUid("");
            } else {
                searchCriteria.setCourtUid("");
            }

            if (Objects.equals(searchCriteria.getReview(), "0")) {
                count = planMapper.getPlanCountByConditions(searchCriteria);
            } else {
                count = planMapper.getReviewCountByConditions(searchCriteria);
            }
        }
        return count;
    }

    /**
     * 0-0 单个法院排期
     * 0-1 单个法院回顾
     * 1-0 区域法院排期
     * 1-1 区域法院回顾
     *
     * @param searchCriteria
     * @return
     */
    @Override
    public Map<String, Object> getReviewByConditions(SearchCriteria searchCriteria) {
        Map<String, Object> result = new HashMap<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //设置分页开始点
        searchCriteria.setPageStart((searchCriteria.getPage() - 1) * searchCriteria.getPageSize());
        //预设结果
        int count = -1;
        List<Map<String, Object>> temp = null;

        if (Objects.equals(searchCriteria.getStatus(), "0") && Objects.equals(searchCriteria.getReview(), "0")) {
//            count = planMapper.getPlanCountByConditions(searchCriteria);
            temp = planMapper.getPlanByConditions(searchCriteria);

        } else if (Objects.equals(searchCriteria.getStatus(), "0") && Objects.equals(searchCriteria.getReview(), "1")) {
            temp = planMapper.getReviewByConditions(searchCriteria);
        } else if (Objects.equals(searchCriteria.getStatus(), "1")) {
            String courtUid = searchCriteria.getCourtUid();
            if (!Objects.equals(courtUid, Constants.CENTRAL_COURT.getUid())) {
                List<String> courtUids = new ArrayList<>();
                for (Court court : Constants.COURT_LIST) {
                    if (Objects.equals(courtUid, court.getUid()) || Objects.equals(courtUid, court.getParentUid())) {
                        courtUids.add(court.getUid());
                    }
                }
                searchCriteria.setCourtIdList(courtUids);
                searchCriteria.setCourtUid("");
            } else {
                searchCriteria.setCourtUid("");
            }

            if (Objects.equals(searchCriteria.getReview(), "0")) {
                temp = planMapper.getPlanByConditions(searchCriteria);
            } else {
                temp = planMapper.getReviewByConditions(searchCriteria);
            }
        }
        for (Map<String, Object> map : temp) {
            CourtRoom courtRoom = Constants.COURTROOM_MAP.get(map.get("courtroomUid"));
            map.put("courtroomName", ObjectUtils.isEmpty(courtRoom)?"未知":courtRoom.getName());
            CaseType caseType = Constants.CASE_TYPE_MAP.get(map.get("caseTypeUid"));
            if (null != caseType) {
                map.put("caseTypeName", caseType.getName());
            }
            map.put("startDate", format.format(map.get("startDate")));
            map.put("lastUpdated", format.format(map.get("lastUpdated")));
        }
        result.put("data", temp);
        return result;
    }

    @Override
    public List<Map<String, Object>> getCaseCount(String courtUid, String caseType, String startDate, String endDate, String status) {

        List<Map<String, Object>> result = new ArrayList<>();
        //将结束日期推后一天
        endDate = addDateOneDay(endDate);

        if (Objects.equals(status, "0")) {
            List<Map<String, Object>> selfResult = planMapper.getCaseCountForSingle(courtUid, caseType, startDate, endDate);
            for (Map<String, Object> temp : selfResult) {
                CaseType caseType1 = Constants.CASE_TYPE_MAP.get(temp.get("caseType"));
                if (!(caseType1 == null)) {
                    temp.put("typeName", caseType1.getName());
                }
            }
            //找出参数法院所有的法庭uid
            for (CourtRoom courtroom : Constants.COURTROOM_LIST) {
                if (Objects.equals(courtUid, courtroom.getCourtUid()) && courtroom.getActive() == 1) {
                    Map<String, Object> temp = new HashMap<>();
                    List<Map<String, Object>> tempList = new ArrayList<>();

                    temp.put("courtroomUid", courtroom.getUid());
                    temp.put("courtroomName", courtroom.getName());
                    for (Map<String, Object> self : selfResult) {
                        if (Objects.equals(self.get("courtroomUid"), courtroom.getUid())) {
                            tempList.add(self);
                        }
                    }
                    temp.put("data", tempList);
                    result.add(temp);
                }
            }


        } else {
            List<String> courtUidList = new ArrayList<>();//参数list
            courtUidList.add(courtUid);
            List<Map<String, Object>> selfResult = planMapper.getCaseCountForArea(courtUidList, caseType, startDate, endDate);
            for (Map<String, Object> temp : selfResult) {

                CaseType caseType1 = Constants.CASE_TYPE_MAP.get(temp.get("caseType"));
                if (!(caseType1 == null)) {
                    temp.put("typeName", caseType1.getName());
                }

            }
            Map<String, Object> self = new HashMap<>();
            self.put("data", selfResult);
            self.put("courtUid", courtUid);
            for (BasisCourt court : Constants.COURT_CONFIG_LIST) {
                if (Objects.equals(courtUid, court.getUid())) {
                    self.put("courtName", court.getAbbreviation());
                }
            }
            //当前参数courtUid的子法院list
            List<String> childCourtUids = CourtUidListUtils.getChildrenCourtUidList(courtUid);
            self.put("length", childCourtUids.size());
            result.add(self);
            //遍历取得下级法院区域数据
            for (String childCourtUid : childCourtUids) {
                courtUidList.clear();
                courtUidList.add(childCourtUid);
                for (Court court : Constants.COURT_LIST) {
                    if (Objects.equals(childCourtUid, court.getParentUid())) {
                        courtUidList.add(court.getUid());
                    }
                }
                List<Map<String, Object>> childResult = planMapper.getCaseCountForArea(courtUidList, caseType, startDate, endDate);
                for (Map<String, Object> temp : childResult) {
                    CaseType caseType1 = Constants.CASE_TYPE_MAP.get(temp.get("caseType"));
                    if (!(caseType1 == null)) {
                        temp.put("typeName", caseType1.getName());
                    }
                }
                Map<String, Object> child = new HashMap<>();
                child.put("data", childResult);
                child.put("courtUid", childCourtUid);

                List<String> tempCourtUids = CourtUidListUtils.getChildrenCourtUidList(childCourtUid);
                for (BasisCourt court : Constants.COURT_CONFIG_LIST) {
                    if (Objects.equals(childCourtUid, court.getUid())) {
                        child.put("courtName", court.getAbbreviation());
                    }
                }
                child.put("length", tempCourtUids.size());
                result.add(child);
            }
        }

        return result;
    }

    /**
     * @param courtUid
     * @param caseType
     * @param startDate
     * @param endDate
     * @param status    0表示单个法院，1表示区域法院
     * @return
     */
    @Override
    public List<Map<String, Object>> getCaseTimeCount(String courtUid, String caseType, String startDate, String endDate, String status) {
        List<Map<String, Object>> result = new ArrayList<>();

        //将结束日期推后一天
        endDate = addDateOneDay(endDate);

        if (Objects.equals(status, "0")) {
            //单个法院按法庭分组
            List<Map<String, Object>> totalResult = planMapper.getCaseTimeCountForSingle(courtUid, caseType, startDate, endDate);
            //找出参数法院所有的法庭uid
            for (CourtRoom courtroom : Constants.COURTROOM_LIST) {
                if (Objects.equals(courtUid, courtroom.getCourtUid()) && courtroom.getActive() == 1) {
                    Map<String, Object> temp = new HashMap<>();
                    List<Map<String, Object>> tempList = new ArrayList<>();

                    temp.put("courtroomUid", courtroom.getUid());
                    temp.put("courtroomName", courtroom.getName());
                    for (Map<String, Object> self : totalResult) {
                        if (Objects.equals(self.get("courtroomUid"), courtroom.getUid())) {
                            CaseType caseType1 = Constants.CASE_TYPE_MAP.get(self.get("caseType"));
                            if (!(caseType1 == null)) {
                                self.put("typeName", caseType1.getName());
                            }
                            tempList.add(self);
                        }
                    }
                    temp.put("data", tempList);
                    result.add(temp);
                }
            }

        } else {
            //区域法院
            List<Map<String, Object>> totalResult = planMapper.getCaseTimeCountForArea(caseType, startDate, endDate);
            Map<String, Object> self = new HashMap<>();
            self.put("courtUid", courtUid);
            List<String> selfChildren = CourtUidListUtils.getChildrenCourtUidList(courtUid);
            self.put("length", selfChildren.size());
            for (BasisCourt court : Constants.COURT_CONFIG_LIST) {
                if (Objects.equals(courtUid, court.getUid())) {
                    self.put("courtName", court.getAbbreviation());
                }
            }
            List<Map<String, Object>> dataList = new ArrayList<>();
            for (Map<String, Object> oneResult : totalResult) {
                if (Objects.equals(courtUid, oneResult.get("courtUid"))) {
                    Map<String, Object> tempData = new HashMap<>();
                    tempData.put("caseType", oneResult.get("caseType"));
                    tempData.put("typeName", Constants.CASE_TYPE_MAP.get(tempData.get("caseType")).getName());
                    tempData.put("timeLong", ((double) Math.round(((BigDecimal) oneResult.get("timeLong")).doubleValue() / 3600 * 10)) / 10);
                    dataList.add(tempData);
                }
            }
            self.put("data", dataList);
            result.add(self);

            for (String childCourtUid : selfChildren) {
                Map<String, Object> child = new HashMap<>();
                List<String> parentChildUids = CourtUidListUtils.getChildrenCourtUidList(childCourtUid);
                child.put("courtUid", childCourtUid);
                child.put("length", parentChildUids.size());
//                child.put("courtName", Constants.COURT_MAP.get(childCourtUid).getName());
                for (BasisCourt court : Constants.COURT_CONFIG_LIST) {
                    if (Objects.equals(childCourtUid, court.getUid())) {
                        child.put("courtName", court.getAbbreviation());
                    }
                }
                parentChildUids.add(childCourtUid);
                List<Map<String, Object>> childDataList = new ArrayList<>();
                //先做成key为a1,a2，value为时长的map,此处需先统计为double，不然除以3600会直接取整
                Map<String, Object> tempData = new HashMap<>();
                for (Map<String, Object> oneResult : totalResult) {
                    if (parentChildUids.contains(oneResult.get("courtUid").toString())) {
                        if (tempData.get(oneResult.get("caseType")) == null) {
                            tempData.put((String) oneResult.get("caseType"), 0.0);
                        }
                        tempData.put((String) oneResult.get("caseType"), (double) tempData.get(oneResult.get("caseType")) + bigToDouble(oneResult.get("timeLong")));
                    }
                }
                //将map整理进List
                for (Map.Entry entry : tempData.entrySet()) {
                    Map<String, Object> tempMap = new HashMap<>();
                    tempMap.put("caseType", entry.getKey());
                    tempMap.put("typeName", Constants.CASE_TYPE_MAP.get(tempMap.get("caseType")).getName());
                    tempMap.put("timeLong", ((double) Math.round((double) entry.getValue() / 3600 * 10)) / 10);
                    childDataList.add(tempMap);
                }
                child.put("data", childDataList);
                result.add(child);
            }

        }


        return result;
    }

    public List<Map<String, Object>> getOnTimeCount(String courtUid, String startDate, String endDate, String status) {
        List<Map<String, Object>> result = new ArrayList<>();
        //将结束日期推后一天
        endDate = addDateOneDay(endDate);

        if (Objects.equals(status, "0")) {
            //单个法院按
            List<Map<String, Object>> singleResults = trialMapper.getOnTimeCountForSingle(courtUid, startDate, endDate);
            Map<String, Object> resultMap = new HashMap<>();
            int[] countNumber = {0, 0, 0};
            for (Map<String, Object> singleResult : singleResults) {
                if (ObjectUtils.isEmpty(singleResult.get("delaytime"))) {
                    continue;
                }
                countNumber(singleResult, countNumber);
            }
            resultMap.put("courtUid", courtUid);
            for (BasisCourt court : Constants.COURT_CONFIG_LIST) {
                if (Objects.equals(courtUid, court.getUid())) {
                    resultMap.put("courtName", court.getAbbreviation());
                }
            }
            resultMap.put("latetimeNum", countNumber[2]);
            resultMap.put("ontimeNum", countNumber[1]);
            resultMap.put("advanceNum", countNumber[0]);
            result.add(resultMap);
        } else {
            //区域法院准点统计
            List<Map<String, Object>> areaResults = trialMapper.getOnTimeCountForArea(startDate, endDate);
            Map<String, Object> self = new HashMap<>();
            self.put("courtUid", courtUid);
            List<String> selfChildren = CourtUidListUtils.getChildrenCourtUidList(courtUid);
            self.put("length", selfChildren.size());
            for (BasisCourt court : Constants.COURT_CONFIG_LIST) {
                if (Objects.equals(courtUid, court.getUid())) {
                    self.put("courtName", court.getAbbreviation());
                }
            }
            int[] countNumber = {0, 0, 0};
            for (Map<String, Object> areaResult : areaResults) {
                if (Objects.equals(areaResult.get("courtUid"), courtUid)) {
                    if (ObjectUtils.isEmpty(areaResult.get("delaytime"))) {
                        continue;
                    }
                    countNumber(areaResult, countNumber);
                }
            }
            self.put("latetimeNum", countNumber[2]);
            self.put("ontimeNum", countNumber[1]);
            self.put("advanceNum", countNumber[0]);
            result.add(self);
            for (String childCourtUid : selfChildren) {
                Map<String, Object> child = new HashMap<>();
                List<String> parentChildUids = CourtUidListUtils.getChildrenCourtUidList(childCourtUid);
                child.put("courtUid", childCourtUid);
                child.put("length", parentChildUids.size());
                for (BasisCourt court : Constants.COURT_CONFIG_LIST) {
                    if (Objects.equals(childCourtUid, court.getUid())) {
                        child.put("courtName", court.getAbbreviation());
                    }
                }
                parentChildUids.add(childCourtUid);
                int[] countNumber1 = {0, 0, 0};
                for (Map<String, Object> areaResult : areaResults) {
                    if (parentChildUids.contains(areaResult.get("courtUid").toString())) {
                        if (ObjectUtils.isEmpty(areaResult.get("delaytime"))) {
                            continue;
                        }
                        countNumber(areaResult, countNumber1);
                    }
                }
                child.put("latetimeNum", countNumber1[2]);
                child.put("ontimeNum", countNumber1[1]);
                child.put("advanceNum", countNumber1[0]);
                result.add(child);
            }
        }
        return result;
    }

    public Map<String, Object> selectJudgeAndSecretary(String courtUid) {
        Map<String, Object> result = new HashMap<>();
        result.put("judgeList", userMapper.selectJudgeByCourtUid(courtUid, null));
        result.put("secretaryList", userMapper.selectSecretaryByCourtUid(courtUid, null));
        return result;
    }

    public List<Map<String, String>> getAllCaseType() {
        List<Map<String, String>> result = new ArrayList<>();
        Map<String, String> a1 = new HashMap<>();
        a1.put("uid", "a1");
        a1.put("name", "刑事");
        result.add(a1);
        Map<String, String> a2 = new HashMap<>();
        a2.put("uid", "a2");
        a2.put("name", "民事");
        result.add(a2);
        Map<String, String> a3 = new HashMap<>();
        a3.put("uid", "a3");
        a3.put("name", "执行");
        result.add(a3);
        Map<String, String> a4 = new HashMap<>();
        a4.put("uid", "a4");
        a4.put("name", "赔偿");
        result.add(a4);
        Map<String, String> a5 = new HashMap<>();
        a5.put("uid", "a5");
        a5.put("name", "行政");
        result.add(a5);
        Map<String, String> a6 = new HashMap<>();
        a6.put("uid", "a6");
        a6.put("name", "信访");
        result.add(a6);
        Map<String, String> a7 = new HashMap<>();
        a7.put("uid", "a7");
        a7.put("name", "其他");
        result.add(a7);
        return result;
    }

    public List<Map<String, String>> getAllOnTimeType() {
        List<Map<String, String>> result = new ArrayList<>();
        Map<String, String> a1 = new HashMap<>();
        a1.put("uid", "1");
        a1.put("name", "提前");
        result.add(a1);
        Map<String, String> a2 = new HashMap<>();
        a2.put("uid", "2");
        a2.put("name", "准点");
        result.add(a2);
        Map<String, String> a3 = new HashMap<>();
        a3.put("uid", "3");
        a3.put("name", "晚点");
        result.add(a3);
        return result;
    }

    @Override
    public List<Map<String, Object>> getTechnologyCourtRate(String courtUid) {
        List<Map<String, Object>> result = new ArrayList<>();
        Map<String, Object> self = new HashedMap();
        List<String> courtUids = CourtUidListUtils.getChildrenCourtUidList(courtUid);
        self.put("courtUid", courtUid);
        self.put("length", courtUids.size());
        for (BasisCourt basisCourt : Constants.COURT_CONFIG_LIST) {
            if (Objects.equals(basisCourt.getUid(), courtUid)) {
                self.put("threeNum", basisCourt.getThirdCourtNum());
                self.put("num", basisCourt.getTechnicalCourtNum());
                self.put("totalNum", basisCourt.getAllCourtNum());
                self.put("name", basisCourt.getAbbreviation());
                if (basisCourt.getAllCourtNum() <= 0) {
                    self.put("rate", 0);
                } else {
                    self.put("rate", basisCourt.getTechnicalCourtNum() * 100 / basisCourt.getAllCourtNum());
                }
            }
        }
        result.add(self);
        for (String childCourtUid : courtUids) {
            Map<String, Object> child = new HashedMap();
            List<String> childrenCourtUidList = CourtUidListUtils.getChildrenCourtUidList(childCourtUid);
            child.put("courtUid", childCourtUid);
            child.put("length", childrenCourtUidList.size());
            int num = 0;
            int threeNum = 0;
            int totalNum = 0;
            for (BasisCourt basisCourt : Constants.COURT_CONFIG_LIST) {
                if (Objects.equals(basisCourt.getUid(), childCourtUid)) {
                    child.put("name", basisCourt.getAbbreviation());
                }
                if (Objects.equals(basisCourt.getUid(), childCourtUid) || Objects.equals(childCourtUid, basisCourt.getParentUid())) {
                    num = num + basisCourt.getTechnicalCourtNum();
                    threeNum = threeNum + basisCourt.getThirdCourtNum();
                    totalNum = totalNum + basisCourt.getAllCourtNum();
                }
            }
            child.put("totalNum", totalNum);
            child.put("threeNum", threeNum);
            child.put("num", num);

            if (totalNum == 0) {
                child.put("rate", 0);
            } else {
                child.put("rate", num * 100 / totalNum);
            }
            result.add(child);
        }

        return result;
    }

    @Override
    public List<Map<String, Object>> getCaseCountExport(String startDate, String endDate) {
        List<Map<String, Object>> result = new ArrayList<>();
        List<Map<String, Object>> countExports = planMapper.getCaseCountExport(startDate, endDate);
        for (Court court : Constants.COURT_LIST) {
            Map<String, Object> map = new HashMap<>();
            map.put("courtName", court.getName());
            map.put("count", 0);
            map.put("a1", 0);
            map.put("a2", 0);
            map.put("a3", 0);
            map.put("a4", 0);
            map.put("a5", 0);
            map.put("a6", 0);
            map.put("a7", 0);
            int count = 0;
            for (Map<String, Object> countExport : countExports) {
                if (Objects.equals(court.getUid(), countExport.get("courtUid"))) {
                    if (Objects.equals(countExport.get("category"), null) || Objects.equals(countExport.get("category"), "a7")) {
                        map.put("a7", (int) map.get("a7") + (int) (long) countExport.get("count"));
                    } else {
                        map.put((String) countExport.get("category"), countExport.get("count"));
                    }
                    count = count + (int) (long) countExport.get("count");
                    map.put("count", count);
                }
            }
            result.add(map);
        }
        return result;
    }


    //将结束日期推后一天
    public static String addDateOneDay(String endDate) {
        if (!ObjectUtils.isEmpty(endDate)) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Calendar cal = Calendar.getInstance();
            try {
                cal.setTime(format.parse(endDate));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            cal.add(Calendar.DAY_OF_MONTH, 1);// 今天+1天
            return format.format(cal.getTime());
        }
        return null;
    }

    //BigDecimal类型转换
    public double bigToDouble(Object obj) {
        return ((BigDecimal) obj).doubleValue();
    }

    //统计准点数目
    public int[] countNumber(Map<String, Object> map, int[] result) {
        if ((long) map.get("delaytime") < 0 - Constants.ON_TIME_BEFORE) {
            result[0]++;
        } else if ((long) map.get("delaytime") > Constants.ON_TIME_AFTER) {
            result[2]++;
        } else {
            result[1]++;
        }
        return result;
    }


}
